package com.ywm.eduOrder.controller;


import com.ywm.commonUtil.R;
import com.ywm.eduOrder.service.TPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-06-06
 */
@RestController
@RequestMapping("/eduOrde/edu-payLog")
public class TPayLogController {
    @Autowired
    private TPayLogService payLogService;

    //生成微信支付二维码
    @GetMapping("/createNative/{orderNo}")
    public R createNative(@PathVariable String orderNo){
        //返回二维码地址还有其他信息
        Map map=payLogService.createNative(orderNo);
        System.out.println("-------------------------------------------");
        System.out.println("返回二维码map集合");
        System.out.println(map);
        System.out.println("-------------------------------------------");
        return R.ok().data(map);
    }
    //查询订单支付状态
    @GetMapping("/queryPayStatus/{orderNo}")
    public R queryPayStatus(@PathVariable String orderNo){
        Map map=payLogService.queryPayStatus(orderNo);
        if(map==null){
            return R.error().message("支付出错 ");
        }
        System.out.println("===========================================");
        System.out.println("订单状态");
        System.out.println(map);
        System.out.println("===========================================");
        //获取订单状态
        if("支付成功".equals(map.get("trade_state_desc"))){
            System.out.println(111111);
            //添加记录到支付表，更新订单表订单状态
            payLogService.updateOrdersStatus(map);
            return R.ok().message("支付成功").code(5000);
        }
        System.out.println(2222222);
        return R.ok().message("支付中");
    }
}

